﻿// -----------------------------------------------------------------------
// <copyright file="RectConverter.cs" company="Christoph van der Fecht">
// This code can be used in Comercial, free and opensource projects
// </copyright>
// -----------------------------------------------------------------------

namespace MediaTool
{
    using System;
    using System.Windows;
    using System.Windows.Data;

    /// <summary>
    /// Multi value binder for the rectangle.
    /// </summary>
    public class RectConverter : IMultiValueConverter
    {
        /// <summary>
        /// Converts the values into a Rectangle object.
        /// </summary>
        /// <param name="values">Array of all values.</param>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="parameter">provided parameters.</param>
        /// <param name="culture">CultureInfo object.</param>
        /// <returns>A Rectanlge with the provided paramters.</returns>
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double width = 0.0;
            double height = 0.0;

            try
            {
                width = (double)values[0];
                height = (double)values[1];
            }
            catch (Exception)
            {
                width = 1.0;
                height = 1.0;
            }

            return new Rect(0.0, 0.0, width, height);

        }

        /// <summary>
        /// Converts the provided rectangle back into its values.
        /// </summary>
        /// <param name="value">The rectangle to convert back</param>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="parameter">provided parameters.</param>
        /// <param name="culture">CultureInfo object.</param>
        /// <returns>Returns a array of values from the provided rectangle.</returns>
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
